home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
001-025
/
002
/
make
/
token.c
< prev
Wrap
C/C++ Source or Header
|
1995-03-13
|
2KB
|
98 lines
#include <stdio.h>
#include <ctype.h>
#include "make.h"
static char *stripwh ();
/*
* Get next token from the string. Return a pointer to it, or NULL.
* Adjust pointer to point to next part of string.
* The string is modified.
* A token consists of any number of non-white characters.
*/
char *token (strpp)
char **strpp;
{
register char *s;
register char *beg = NULL;
DBUG_ENTER ("token");
DBUG_3 ("tok", "get next token from '%s'", *strpp);
(void) stripwh (strpp);
if (**strpp) {
beg = s = *strpp;
while (*s && !isspace (*s)) {
++s;
}
if (*s) {
*s++ = '\0';
}
*strpp = s;
DBUG_3 ("tok", "found token '%s'", beg);
}
DBUG_RETURN (beg);
}
/*
* Parse character escape-sequences in a line of text.
* <EscChar><EscChar> = <EscChar>
* <EscChar>n = newline, and so on
* <EscChar><char> = <char>
* The string is truncated at the first non-escaped occurance of 'comchar'.
*/
void escape (str, comchar)
char *str;
char comchar;
{
register char *d;
register char c;
DBUG_ENTER ("escape");
for (d = str; *str && *str != comchar; ++str) {
if (*str == ESCCHAR && *(str + 1)) {
switch ((c = *++str)) {
case ESCCHAR:
*d++ = ESCCHAR;
break;
case 'n':
*d++ = '\n';
break;
case 'r':
*d++ = '\r';
break;
case 't':
*d++ = '\t';
break;
case 'b':
*d++ = '\b';
break;
case 'f':
*d++ = '\f';
break;
default:
*d++ = c;
break;
}
} else {
*d++ = *str;
}
}
*d++ = 0;
DBUG_VOID_RETURN;
}
static char *stripwh (strpp)
char **strpp;
{
register char *s;
s = *strpp;
while (isspace (*s)) {
++s;
}
return (*strpp = s);
}